<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 销售渠道库存分配设置
 * @package  htdocs
 * @subpackage  quanliadmin
 * @create by allen.qiang
 */

class pa_storeChannelConfig {

    public function execute() {
        global $G_PGLOB ;
        if (isset($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1:
                    $this->init();
                    break;

                default:
                    $G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
                    $G_PGLOB->smarty->display('comm/error.tpl');

            }
        }
    }

    private function init() {

        global $G_PGLOB;

        //查询渠道总数
        $search_channel_num = 'SELECT COUNT(*) num FROM 3rd_channel';
        $channelNum         = $G_PGLOB->DBCA->stmt_query($search_channel_num);

        //获取渠道
        $search_channel_list = 'SELECT * FROM 3rd_channel';
        $channelList         = $G_PGLOB->DBCA->stmt_query($search_channel_list);

        //传参数组
        $c = array(
            'count' => $channelNum[0]->num, //渠道总数
            'channelList' => array()       //存储商品在各个渠道所占比例信息
        );

        if( $channelList ){

            foreach( $channelList as $list ){

                //记录分配比例
                $percent = '输入库存分配比例';

                //查询商品在此渠道的分配信息
                $search_percent = 'SELECT * FROM wms_goodsstore_percent WHERE channelID=?';
                $result         = $G_PGLOB->DBCA->stmt_query( $search_percent , 'i' , $list->channelID );

                if( $result ){
                    $percent = $result[0]->percent;
                }

                $c['channelList'][] = array(
                    'channelID'   => $list->channelID,
                    'channelName' => $list->channelName,
                    'percent'     => $percent
                );

            }

        }

        $G_PGLOB->smarty->assign_by_ref('info' , $c);
        $G_PGLOB->smarty->display('system/goodsStorePercent.tpl');

    }


}